package com.three.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.three.entity.Backlightcolor;
import com.three.mapper.BacklightcolorMapper;
import com.three.service.BacklightcolorService;
import com.three.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BacklightcolorServiceImpl implements BacklightcolorService {

    @Autowired
    private BacklightcolorMapper backlightcolorMapper;

    @Override
    public R list() {
    List<Backlightcolor> all = backlightcolorMapper.list();
    return R.ok(all);
    }

    @Override
    public R BacklightcolorAll(Integer pageNum, Integer pageSize, Backlightcolor backlightcolor) {
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        //查询所有
        List<Backlightcolor> backlightcolorList = backlightcolorMapper.BacklightcolorAll(backlightcolor);
        //封装分页数据
        PageInfo<Backlightcolor> pageInfo = new PageInfo<>(backlightcolorList);
        return R.ok(pageInfo);
    }
// 添加
    @Override
    public R add(Backlightcolor backlightcolor) {
        int i = backlightcolorMapper.insertSelective(backlightcolor);
        if (i>0){
            return R.ok();
        }
        return R.error("添加失败");
    }

    //编辑
    @Override
    public R edit(Backlightcolor backlightcolor) {
        int i = backlightcolorMapper.updateByPrimaryKeySelective(backlightcolor);
        if (i>0){
            return R.ok();
        }
        return R.error("修改失败");
    }

    @Override
    public R delete(Integer backlightcolorid) {
        int i = backlightcolorMapper.deleteByPrimaryKey(backlightcolorid);
        if (i>0){
            return R.ok();
        }
        return R.error("删除失败");

    }


}
